<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
    <div class="layui-carousel" id="test1">
        <div carousel-item>
          <div><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqimg.cdnmama.com%2Fgz%2Fdata%2Fattachment%2Fforum%2F2020%2F12%2F07%2Fb3139b9daa6a4f04ab7d02e1e9931dc7_w300X127_w196X83.jpeg%3FimageView2%2F0%2Fw%2F700%2Fh%2F700&refer=http%3A%2F%2Fqimg.cdnmama.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661586636&t=1e56d2dd6e1b797963710573376e6cce"
            style="width: 100%;height: 100%;"
            ></div>
          <div><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.8bb.com%2Fd%2Ffile%2F20201026%2F1603675948623908.png&refer=http%3A%2F%2Fwww.8bb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661586636&t=6c1be11e28e48a3760165c4d99eb1320"
            style="width:100% ;height:100%;"
            ></div>
      
        </div>
    </div>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="fm1">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">职位</label>
                            <div class="layui-input-inline">
                                <input type="text" name="position" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">薪资</label>
                            <div class="layui-input-inline">
                                <input type="text" name="wage" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">公司</label>
                            <div class="layui-input-inline">
                                <input type="text" name="company" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">地区</label>
                            <div class="layui-input-inline">
                                <input type="text" name="region" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 批量删除 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="export"> 导出 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="import"> 导入 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="templatedownload"> 模板下载 </button>
            </div>
        </script>

        <table class="layui-hide" id="parttimeholiday" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use('carousel', function(){
      var carousel = layui.carousel;
      //建造实例
      carousel.render({
        elem: '#test1'
        ,width: '100%' //设置容器宽度
        ,arrow: 'always'
        
        
         //始终显示箭头
        //,anim: 'updown' //切换动画方式
      });
    });
    </script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#parttimeholiday',
            url: 'http://localhost:8080/parttimeholiday/parttimeholidaylist',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'position', width: 80, title: '职位'},
                {field: 'wage', width: 80, title: '薪资', sort: true},
                {field: 'company', width: 150, title: '公司'},
                {field: 'telephone', title: '电话', minWidth: 70},
                {field: 'region', width: 150, title: '地区'},
                {field: 'description', width: 250, title: '描述'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('parttimeholiday', {
                page: {
                    curr: 1
                }
                , where: {
                    "position":data.field.position,
                    "wage":data.field.wage,
                    "company":data.field.company,
                    "region":data.field.region
                    
                }
            }, true);

            return false;
        });

        //头工具栏事件  
        // table.on('toolbar(currentTableFilter)', function (obj) {
        //     console.log(obj);
        //     var checkStatus = table.checkStatus(obj.config.id);
        //     if(obj.event === 'templatedownload'){
        //         location.href="http://localhost:8080/parttimeholiday/templateDownload";
        //     }else if(obj.event === 'export'){
        //         local.href="http://localhost:8080/parttimeholiday/export";
        //     }else if(obj.event === 'import'){
        //         layer.open({
        //                 title: '兼职信息导入',
        //                 shade: 0.2,
        //                 type: 2,
        //                 shadeClose: true,   // 点别的地方 是否关闭当前 layer    true收关闭   false 不关闭
        //                 area: ['50%', '50%'],
        //                 fixed: true, //不固定
        //                 maxmin: true,
        //                 content: './parttimeholidayimport.html',
        //                 end: function (index) {
        //                     table.reload('paperTable');
        //                 }
        //             });
        //     }


            // switch (obj.event) {
                
            //     case 'export':
            //         // 数据导出到 excel 中
            //         // $("#fm1").serialize()  获取表单的输入的表单项内容  拼成正确的参数格式
            //         location.href="http://localhost:8080/paper/export?"+$("#fm1").serialize();
            //         break;    
                
            //     case 'import':
            //     layer.open({
            //             title: '学员信息导入',
            //             shade: 0.2,
            //             type: 2,
            //             shadeClose: true,   // 点别的地方 是否关闭当前 layer    true收关闭   false 不关闭
            //             area: ['50%', '80%'],
            //             fixed: true, //不固定
            //             maxmin: true,
            //             content: './paperImport.html',
            //             end: function (index) {
            //                 table.reload('paperTable');
            //             }
            //         });
            //         break;  
            //         // 模板下载
            //     case 'templatedownload':
            //         //记住这种 发送请求的方式
            //         location.href="http://localhost:8080/parttimeholiday/templateDownload";
            //         break;

            // };
        // });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: './parttimeholidayadd.html',
                    end: function (index) {

                    table.reload('parttimeholiday');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  
                    // 监听删除操作
                    //可以在这里实现批量删除   
                    var checkStatus = table.checkStatus(obj.config.id); 

                    //获选选中行的数组
                    var data = checkStatus.data;
                    console.log(data)
                    var arr = [];    
                    //得到选中行的数据的id  放入一个新的数组
                    for(var i=0;i<data.length;i++){
                        arr.push(data[i].id);    //   arr   [3,5]
                    }
                    // 数组转字符串
                    var ids = arr.join(",");  //  "3,5"
                    // 把要删除的数据 的 id 拼成的字符串传到后台      
                    $.get("http://localhost:8080/parttimeholiday/deleteparttimeholidaybyids",{"ids":ids},function(result){
                        // result 是后台 响应回来的 json 格式的对象   就是后台那个 R 
                        if (result.code == 200) {
                            // 弹出层组件
                            layer.msg("删除成功");
                            //在页面上删除 对应的 行
                            // obj.del(); //删除对应行（tr）的DOM结构
                            // 让表格重新获取下 数据源的数据
                            table.reload('parttimeholiday');  // 删除完  重新加载下表格
                        } else {
                            layer.msg("删除失败");
                        }  

                    },"json")

            }else  if(obj.event === 'export'){
             
                window.location.href="http://localhost:8080/parttimeholiday/export"

            }else  if(obj.event === 'import'){
                // alert(123);
                layer.open({
                        title: '兼职信息导入',
                        shade: 0.2,
                        type: 2,
                        shadeClose: true,   // 点别的地方 是否关闭当前 layer    true收关闭   false 不关闭
                        area: ['50%', '80%'],
                        fixed: true, //不固定
                        maxmin: true,
                        content: './parttimeholidayimport.html',
                        end: function (index) {
                            table.reload('parttimeholiday');
                        }
                    });

            }else  if(obj.event === 'templatedownload'){
            
                window.location.href="http://localhost:8080/parttimeholiday/templateDownload"
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            
            if (obj.event === 'edit') {
                
                localStorage.setItem("parttimeholiday", JSON.stringify(data));  

                var index = layer.open({
                    title: '编辑信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: './parttimeholidayedit.html',
                    end: function (index) {
                        table.reload('parttimeholiday');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    $.get("http://localhost:8080/parttimeholiday/deleteparttimeholiday",{"id":data.id},function (result){
                        if (result.code == 200) {
                            layer.msg("删除成功");
                            obj.del(); //删除对应行（tr）的DOM结构
                            table.reload('parttimeholiday');  // 删除完  重新加载下表格
                        } else {
                            layer.msg("删除失败");
                        }
                    },"json");
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>